<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
<div id="app">
    <!-- computed : 某些结果是基于之前数据实时计算出来的，我们可以利用计算属性。来完成 -->
    <ul>
        <li>西游记； 价格：{{xyjPrice}}，数量：<input type="number" v-model="xyjNum"/></li>
        <li>水浒传； 价格：{{shzPrice}}，数量：<input type="number" v-model="shzNum"/></li>
        <li>总价：{{totalPrice}}</li>
        msg: {{msg}}
    </ul>
</div>
<script src="../../node_modules/vue/dist/vue.js"></script>

<script>
    let app = new Vue({
        el: "#app",
        data: {
            xyjPrice: 98.5,
            shzPrice: 85,
            xyjNum: 1,
            shzNum: 1,
            msg : "",
        },

        // 计算属性
        computed: {
            totalPrice(){
                return this.shzNum * this.shzPrice + this.xyjNum * this.xyjPrice;
            }
        },
    //    侦听器
        watch : {
            // 监听对象(新值，旧值)
            xyjNum(newValue, oldValue) {
                if(newValue >= 3) {
                    this.msg = "超库存";
                    this.xyjNum = 3;
                } else {
                    this.msg = "";
                }
            }
        }


    })

</script>

</body>

</html>